package com.tan.bean;

import com.alibaba.druid.pool.DruidDataSource;
import com.tan.autoConfigration.DatasourceProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;

/**
 * @author by 团子
 * @Classname CreateDruid
 * @Description TODO
 * @Date 2022/1/5 16:39
 * @Created by 团子
 */
@Configuration
@EnableConfigurationProperties(DatasourceProperties.class)
public class CreateDruid {

    @Autowired
    private DatasourceProperties datasourceProperties;

    @Bean
    public DataSource createDataSource(){
        DruidDataSource dataSource = new DruidDataSource();
        dataSource.setUsername(datasourceProperties.getUsername());
        dataSource.setUrl(datasourceProperties.getUrl());
        dataSource.setDriverClassName(datasourceProperties.getDriverClassName());
        dataSource.setPassword(datasourceProperties.getPassword());
        return dataSource;
    }
}
